# @Time  : 2021/7/28 9:53
# @Author: zhanfengzhen
# @Email : zhanfengzhen@126.com
# @File  : conftest.py
# !/usr/bin/env python
# -*- coding: UTF-8 -*-
import os
import pytest
import yaml
from selenium import webdriver



#复用浏览器获取cookies
@pytest.fixture()
def get_cookies():
    opt = webdriver.ChromeOptions()
    opt.debugger_address = '127.0.0.1:9222'
    dri = webdriver.Chrome(options=opt)
    dri.get("https://work.weixin.qq.com/wework_admin/frame#index")
    cookies = dri.get_cookies()
    return cookies

#写入yaml文件
@pytest.fixture()
def get_cookieYaml(get_cookies):
    ff = os.path.dirname(__file__)
    datas = os.path.join(ff, './cookiesDatas.yml')
    with open(datas, 'w+', encoding='utf-8') as f:
        yaml.safe_dump(get_cookies, f)


def get_bumen():
    cs = os.path.dirname(__file__)
    datas = os.path.join(cs, './po/depDatas.yml')
    with open(datas, encoding='utf-8') as f:
        datas = yaml.safe_load(f)
    return datas

@pytest.fixture(params=get_bumen())
def bumen(request):
    return request.param


def pytest_collection_modifyitems(items):
    """
    测试用例收集完成时，将收集到的item的name和nodeid的中文显示在控制台上
    :return:
    """
    for item in items:
        #item.name 测试用例的名字
        #item.nodeid 测试用例的路径
        item.name = item.name.encode("utf-8").decode("unicode_escape")
        item._nodeid = item.nodeid.encode("utf-8").decode("unicode_escape")
